package com.xh.bussiness.scheduletask;

import com.xh.bussiness.thirdapi.xiaoguanjia.bean.request.XgjBaseRequest;
import com.xh.bussiness.thirdapi.xiaoguanjia.service.IXiaoGuanJiaService;
import com.xh.bussiness.thirdapi.xuebang.service.IXuebangService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Component
public class XuebangScheduleTask {

    @Value("${xuebang.asyncTeachers}")
    private Boolean asyncTeachers;
    @Value("${xuebang.asyncClasses}")
    private Boolean asyncClasses;
    @Value("${xuebang.asyncStudents}")
    private Boolean asyncStudents;

    @Autowired
    private IXuebangService xuebangService;

    public static void main(String[] args) {
        LocalDate now = LocalDate.now().plusDays(-1);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        System.out.println(now.format(formatter));
    }

    // 每天凌晨一点半
    @Scheduled(cron = "0 30 1 * * ?")
    public void asyncTeachers() {
        if (!asyncTeachers) {
            return;
        }
        xuebangService.syncUser();
    }

    @Scheduled(cron = "0 0 2 * * ?")
    public void asyncClass() {
        if (!asyncClasses) {
            return;
        }
        xuebangService.syncXuebangClass();
    }

    @Scheduled(cron = "0 30 2 * * ?")
    public void asyncStudents() {
        if (!asyncStudents) {
            return;
        }
        xuebangService.syncStudent();
    }

}
